package com.jiang.专题.动态规划.Q338;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/02/18 21:19
 */
class Solution {
    public int[] countBits(int n) {
        int[] res = new int[n + 1];
        int temp = 1;
        for (int i = 1; i <= n; i++) {
            if ((i & (i - 1)) == 0) {
                temp = i;
            }
            res[i] = res[i - temp] + 1;
        }
        return res;
    }
}
